<template>
	<tm-app ref="app">
	<tm-card :status="item['addtime']" statusColor="orange" :title="'order-No：'+item['id']"
		v-for="(item, key) in orderlist" :key="key">
		<template v-slot:action>
			<view class="mb-32 mx-32 round-3 overflow" style="margin-top: -50rpx;border: 0px solid;width:100%;">
				<tm-cell bottomBorder :margin="[0, 0]" :titleFontSize="30" title="product:">
					<template v-slot:right>
						<tm-image preview :width="100" :height="100" :src="item.img"></tm-image>
					</template>
				</tm-cell>
				<tm-cell bottomBorder :margin="[0, 0]" :titleFontSize="30" title="count:">
					<template v-slot:right>
						<tm-text :label="item.orderimg"></tm-text>
					</template>
				</tm-cell>
			<tm-cell bottomBorder :margin="[0, 0]" :titleFontSize="30" title="name:">
				<template v-slot:right>
					<tm-text :label="item.lxr"></tm-text>
				</template>
			</tm-cell>
			<tm-cell bottomBorder :margin="[0, 0]" :titleFontSize="30" title="phone:">
				<template v-slot:right>
					<tm-text :label="item.phone"></tm-text>
				</template>
			</tm-cell>
			<tm-cell bottomBorder :margin="[0, 0]" :titleFontSize="30" title="address:">
				<template v-slot:right>
					<tm-text :label="item.address"></tm-text>
				</template>
			</tm-cell>
			<tm-cell bottomBorder :margin="[0, 0]" :titleFontSize="30" title="price($):">
				<template v-slot:right>
					<tm-text :label="item.payprice"></tm-text>
				</template>
			</tm-cell>
			<tm-cell bottomBorder :margin="[0, 0]" :titleFontSize="30" title="pay(status):">
				<template v-slot:right>
					<tm-text :label="loadPayStatus(item.status)"></tm-text>
				</template>
			</tm-cell>
			<tm-cell bottomBorder :margin="[0, 0]" :titleFontSize="30" title="">
				<template v-slot:right>
					<tm-button :margin="[10]" color="red" :shadow="0" size="small" label="detail" @click="toDetail(item['id'])"></tm-button>
				</template>
			</tm-cell>
			</view>
		</template>
	</tm-card>
	
	</tm-app>
</template>

<script lang="ts" setup>
	import { ref } from "vue"
	import { onLoad } from "@dcloudio/uni-app"
	import { isEmpty } from "@/tmui/tool/function/util";
	import { getOrderByWxid, quitOrder, startOrder, stopOrder, payDjOrder, payPayOrder, delDjOrder } from '@/api/order'
	
	const userid = ref('');
	const acc = ref(2);
	const keys = ref("1");
	const code = ref("3");
	const tabsTitle = ref([])
	const orderlist = ref([])
	const flag = ref(true);
	const showWin = ref(false);
	
	onLoad(() => {
		userid.value = uni.getStorageSync("userid");
		if (isEmpty(userid.value)) {
			uni.navigateTo({
				url: '/pages/auth/auth'
			})
		} else {
			queryOrder('1');
		}
	})
	
	function loadPayStatus(status:any){
		// console.log(status);
		if(status === '1'){
			return "no pay";
		}
		return "pay ok"
	}
	
	
	const queryOrder = async (status : any) => {
		let param = { "wxid": userid.value, "status": status, "code": "1" };
		const result = await getOrderByWxid(param);
		// console.log('ssss::',JSON.stringify(result));
		orderlist.value = result
	}
	
	function toDetail(id:any){
		uni.navigateTo({
			url: `/pages/order/orderDetailPay?id=${id}`
		})
	}
</script>
